<?php

namespace App\Models\User;

use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * App\Models\User\WechatOfficialUser
 *
 * @property int         $id
 * @property string      $user_id 用户id
 * @property string      $openid 微信公众号openid
 * @property int         $subscribe 1 已关注 0 未关注
 * @property string      $appid appid
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @method static Builder|WechatOfficialUser newModelQuery()
 * @method static Builder|WechatOfficialUser newQuery()
 * @method static Builder|WechatOfficialUser query()
 * @method static Builder|WechatOfficialUser whereAppid($value)
 * @method static Builder|WechatOfficialUser whereCreatedAt($value)
 * @method static Builder|WechatOfficialUser whereId($value)
 * @method static Builder|WechatOfficialUser whereOpenid($value)
 * @method static Builder|WechatOfficialUser whereSubscribe($value)
 * @method static Builder|WechatOfficialUser whereUpdatedAt($value)
 * @method static Builder|WechatOfficialUser whereUserId($value)
 * @mixin Eloquent
 */
class WechatOfficialUser extends Model
{
    use HasFactory;

    protected $table = 'user_wechat_official';
    protected $fillable
                     = [
            'user_id',
            'openid',
            'appid',
            'subscribe',
        ];

    /**
     * true 已关注 false  未关注
     * @return bool
     */
    public function isSubscribe(): bool
    {
        return $this->getAttribute('subscribe') == 1;
    }

    public function getUserId()
    {
        return $this->getAttribute('user_id');
    }

    public function getOpenId()
    {
        return $this->getAttribute('openid');
    }

    public function getAppId()
    {
        return $this->getAttribute('appid');
    }
}